import { useMemo } from 'react';
import { useParams as _useParams, useLocation } from 'react-router-dom';

export function useParams() {
  const params = _useParams();
  const location = useLocation();
  const queryParams = useMemo(() => {
    const searchParams = new URLSearchParams(location.search);
    const queryObj = {};
    for (const [key, value] of searchParams.entries()) {
      queryObj[key] = value;
    }
    return queryObj;
  }, [location.search]);
  
  return useMemo(() => ({ ...params, ...queryParams }), [params, queryParams]);
}
